<?php

namespace App\CompanyApi\Requests;

//use Admin\src\Requests\BaseRequest;
use App\Models\JobpositionModel;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;

class JobpositionRequest extends FormRequest
{
    public function rules(): array
    {
        return [
            'position_name' => ['required', 'between:2,8'],
            'region_province' => ['integer', 'required_with_all:region_city,region_region'],
            'region_city' => ['integer', 'required_with_all:region_province,region_region'],
            'region_region' => ['integer', 'required_with_all:region_province,region_city'],
            'salary' => ['required'],
            'salary_type' => ['required', Rule::in(array_keys(JobpositionModel::SALARY_TYPE_LIST))],
            'job_description' => ['required'],
            'selection_date_start' => ['nullable', 'date_format:Y-m-d'],
            'selection_date_end' => ['nullable', 'date_format:Y-m-d', 'after:selection_date_start'],
            'work_time_start' => ['nullable', 'date_format:H:i'],
            'work_time_end' => ['nullable', 'date_format:H:i', 'after:work_time_start'],
            'greeting_message' => ['required',],
            'contact_type' => ['required', Rule::in(array_keys(JobpositionModel::CONTACT_TYPE_LIST))],
            'contact_wechat' => ['required_if:contact_type,' . JobpositionModel::CONTACT_WECHAT, 'array'],
            'contact_dingtalk' => ['required_if:contact_type,' . JobpositionModel::CONTACT_DINGTALK, 'array'],
            'contact_qq' => ['required_if:contact_type,' . JobpositionModel::CONTACT_QQ, 'array'],
            'contact_phone' => ['required_if:contact_type,' . JobpositionModel::CONTACT_MOBILE, 'array'],
            'contact_wechat.*.wechat_number' => ['required_if:contact_type,' . JobpositionModel::CONTACT_WECHAT],
            'contact_wechat.*.wechat_qr_code' => [],
            'contact_dingtalk.*.dingtalk_number' => ['required_if:contact_type,' . JobpositionModel::CONTACT_DINGTALK],
            'contact_dingtalk.*.dingtalk_qr_code' => [],
            'contact_qq.*.qq_number' => ['required_if:contact_type,' . JobpositionModel::CONTACT_QQ,],
            'contact_qq.*.qq_qr_code' => [],
            'contact_phone.*.phone_number' => ['required_if:contact_type,' . JobpositionModel::CONTACT_MOBILE, 'digits:11'],
        ];
    }

    public function messages(): array
    {
        return [
            'position_name.required' => '请填写职位名称。',
            'position_name.between' => '职位名称长度必须在2到8个字符之间。',

            'region_province.integer' => '省份选择错误。',
            'region_province.required_with_all' => '请选择省份。',

            'region_city.integer' => '城市选择错误。',
            'region_city.required_with_all' => '请选择城市。',

            'region_region.integer' => '区/县选择错误。',
            'region_region.required_with_all' => '请选择区/县。',

            'salary.required' => '请填写薪资。',

            'salary_type.required' => '请填写薪资类型。',
            'salary_type.in' => '选择的薪资类型无效。',

            'job_description.required' => '请填写工作描述。',

            'selection_date_start.date_format' => '招聘开始日期格式错误。',
            'selection_date_end.date_format' => '招聘结束日期格式错误。',
            'selection_date_end.after' => '招聘结束日期必须在开始日期之后。',

            'work_time_start.date_format' => '招聘开始时间格式错误。',
            'work_time_end.date_format' => '招聘结束时间格式错误。',
            'work_time_end.after' => '招聘结束时间必须在开始时间之后。',

            'greeting_message.required' => '请填写打招呼语。',

            'contact_type.required' => '请填写联系类型。',
            'contact_type.in' => '选择的联系类型无效。',

            'contact_wechat.required_if' => '请填写微信联系信息。',
            'contact_wechat.array' => '微信联系信息格式错误。',
            'contact_wechat.*.wechat_number.required_if' => '请填写微信号。',

            'contact_qq.required_if' => '请填写QQ联系信息。',
            'contact_qq.array' => 'QQ联系信息格式错误。',
            'contact_qq.*.qq_number.required_if' => '请填写QQ号。',


            'contact_dingtalk.required_if' => '请填写钉钉联系信息。',
            'contact_dingtalk.array' => '钉钉联系信息格式错误。',
            'contact_dingtalk.*.dingtalk_number.required_if' => '请填写钉钉号。',
            

            'contact_phone.required_if' => '请填写手机号联系信息。',
            'contact_phone.array' => '手机号联系信息格式错误。',
            'contact_phone.*.phone_number.required_if' => '，请填写手机号。',
            'contact_phone.*.phone_number.digits' => '手机号必须是11位数字。',
        ];
    }



    public function attributes(): array
    {
        return [
            'position_name' => '职位名称',
            'region_province' => '省份',
            'region_city' => '市',
            'region_region' => '区/县',
            'salary' => '薪资',
            'salary_type' => '薪资类型',
            'job_description' => '工作描述',
            'selection_date_start' => '招聘开始日期',
            'selection_date_end' => '招聘结束日期',
            'work_time_start' => '招聘开始时间',
            'work_time_end' => '招聘结束时间',
            'greeting_message' => '打招呼语',
            'contact_type' => '联系类型',
        ];
    }
}
